import { fromJS } from 'immutable';
import { constants } from '../store';

const defaultState = fromJS({
    topicList: [],
    listList: [],
    RecommendImg: [],
    listTotalPage: 0,
    listPage: 2,
    showScroll: false
})

const changeHomeData = (state,action) => {
  return state.merge({
    topicList: fromJS(action.topicList),
    listList: fromJS(action.listList),
    listTotalPage: fromJS(action.listList.length),
    RecommendImg: fromJS(action.RecommendImg)
  })
};

const homeReducer = (state=defaultState, action) => {
  switch (action.type) {
    case constants.CHANGE_HOME_DATA :
      return changeHomeData(state,action);
    case constants.LOAD_MORE :
      return state.merge({
        listPage: action.currentListPage
      });
    case constants.CHANGE_SCROLL :
      return state.merge({
        showScroll: action.showScroll
      });
    default :
      return state
  }
};

export default homeReducer
